$.fn.numeral = function() {
            $(this).css("ime-mode", "disabled");
            this.bind("keydown",function(event) {
				var code = (event.keyCode ? event.keyCode : event.which);
				if (!$.browser.msie && (event.keyCode == 0x8)){
					return;
				}
				if(code == 13){
					if($.browser.mozilla){
						this.blur();
						this.focus();
					}
				}
				return (code >= 48 && code <= 57) ||(code >= 96 && code <= 105) || (code==37) || (code==39)|| (code==46)|| (code==8)|| (code==9)|| (code==13);
            });

            this.bind("paste", function() {
                var s = clipboardData.getData('text');
                if (!/\D/.test(s));
                value = s.replace(/^0*/, '');
                return false;
            });

            this.bind("dragenter", function() {
                return false;
            });

            this.bind("keyup", function() {
            if (/(^0+)/.test(this.value)) {
                this.value = this.value.replace(/^0*/, '');
                }
            });
        };



KISSY.ready(function(S) { 
	S.Suggest('#k1', '/go3c/suggest.ldo', { autoFocus: false, useShim:false,timerDelay:500,resultFormat: '约%result%条记录' });
});

function doSearch(searchType){
	$('#t1').val(searchType);
	$('#searchform3c').submit();
}

function donothing(vendorId,id){
  $.ajax({ url: "/go3c/click.ldo",cache:false,data:"vendorId="+vendorId+"&id="+id+"&username="});
}

function openDivLogin(){
	var loginDiv = $(document.body).append("<div id=\"loginDiv\" class=\"hidden\" style=\"z-index:999\"></div>"); 
	loginDiv = $('#loginDiv');
	loginDiv.show();
	loginDiv.load("/passport/ajaxLogin.action","random="+Math.random(),function(){
      window.onresize   =   centerDiv;
      window.onscroll   =   centerDiv;
	  centerDiv();
	});
}


function closeDivLogin(){
	$("#loginDiv").hide();
	$("#loginDiv").remove();
    if(window.onresize){
	  window.onresize=null;
	  window.onscroll=null; 
    }
}

function centerDiv(){
		var loginDiv = $('#loginDiv');
		var   d   =   document.documentElement;   
		if(!d)
		{
		  d = document.body; 
		}
		//     首先取得页面现在的左上角相对位置   
		var   x1   =   d.scrollLeft;   
		var   y1   =   d.scrollTop;   
		var   w1   =   d.clientWidth;   
		var   h1   =   d.clientHeight;   
		  

		//     取得浮动层的信息   
		var   w   =   loginDiv.width();   
		if(w>800)
			w= 500;
		var   h   =   loginDiv.height();   
		var   x   =   Math.ceil((w1   -   w)/2)   +   x1;   
		var   y   =   Math.ceil((h1   -   h)/2)   +   y1;   

		loginDiv.css("left",x).css("top",y).css("position","absolute");
}

function doDivLogin(){
	var canSubmit = true;
    if($.trim($("#sign_username").val())==""){
		$("#sign_msg").html("<font color=\"red\">账号不能为空!!</font>");
		canSubmit = false;
		$("#sign_username").focus();
    }else{
		$("#sign_msg").html("");
	}

    if($.trim($("#sign_password").val())==""){
		$("#pwd1_msg").html("<font color=\"red\">密码不能为空!!</font>");
		$("#sign_password").focus();
		canSubmit = false;
    }else{
		$("#pwd1_msg").html("");
	}

	if($("#verifycode").length>0){
		if($.trim($("#verifycode").val())==""){
			$("#verifycode_msg").html("<font color=\"red\">请输入验证码!!</font>");
			canSubmit = false;
			$("#verifycode").focus();
		}else{
			$("#verifycode_msg").html("");
		}
	}
	if(canSubmit){
		var form = $("#loginForm");
		var action = form.attr('action');
		$.getJSON(action,form.serialize(),function(data){
			if(data.bean.result==true){
         		hasLoginCallbackFunc();
			}else{
				var loginDiv = $('#loginDiv');
				$('#errorMsg').val(data.message);
				loginDiv.load("/passport/ajaxLogin.action",form.serialize(),function(){
					loginDiv.css("zIndex","1000").show();
					centerDiv();
				});
			}
		});
	}
}


function hasLoginCallbackFunc(){
	closeDivLogin();
	$("#top_login_div").load("/passport/hasLogin.action","random="+Math.random(),function(){loginSuccessCallBackFunc();});
}

function loginSuccessCallBackFunc(){
	 if(typeof(doLoginSuccessCallBack) =='function'){		 	
		doLoginSuccessCallBack();
  	}
}

function showMessage(msg){
	var messageDiv = $('#message_div');
	if(messageDiv.length<1){
		$(document.body).append("<div id=\"message_div\" class=\"ajaxMessage\"></div>"); 
		messageDiv = $('#message_div');
	}
	if(document.documentElement){
		messageDiv.css("top",document.documentElement.scrollTop);
	}
	messageDiv.html(msg).show();
}

function hideMessage(){
	var messageDiv = $('#message_div');
	messageDiv.hide();
}

function promptMessage(msg){
	var messageDiv = $('#message_div');
	if(messageDiv.length<1){
		$(document.body).append("<div id=\"message_div\" class=\"ajaxMessage\"></div>"); 
		messageDiv = $('#message_div');
	}
	if(document.documentElement){
		messageDiv.css("top",document.documentElement.scrollTop);
	}
	messageDiv.html(msg).fadeIn("slow",function(){messageDiv.hide();});
}


function dobooknothing(vendorId,id){
  $.ajax({ url: "/bookclick.html?vendorId="+vendorId+"&id="+id});
}

function addCookie(name,value,expireDays){
	var cookieString=name+"="+escape(value);
	if(expireDays>0){
		var date=new Date();
		date.setTime(date.getTime()+(expireDays*24*3600*1000));
		cookieString=cookieString+"; expires="+date.toGMTString()+"; domain=.boxz.com; path=/";
	}
	document.cookie=cookieString;
}




function openSelectDomain(){
	var button = $('#toggle_text');
	button.addClass("current");
	var opendiv = $("#popup_domain_div");
	if(opendiv.is(":visible")==false){
		opendiv.show();
		opendiv.css("left",button.offset().left);
		opendiv.css("top",button.offset().top + button.height()-1);
		opendiv.show();

		opendiv.mouseup(function() {
                return false;
        });

		$(document).mouseup(function(e) {
                if( $(e.target).parent("#popup_domain_div").length==0){
                    closeSelectDomain();
                }
        });
	}
}

function closeSelectDomain(){
	var button = $('#toggle_text');
	button.removeClass("current");
	var opendiv = $("#popup_domain_div");
	opendiv.hide();
}

$(document).ready(function(){
	$('#shop_top_a').hover(function(){$(this).children('ul.toppopcontainer').show();},function(){$(this).children('ul.toppopcontainer').hide();});
	$('#category_top_a').hover(function(){$(this).children('ul.toppopcontainer').show();},function(){$(this).children('ul.toppopcontainer').hide();});
});
